package top.wfzzq.ds.sort;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;

/**
 * 排序演示
 * 
 * @author wanghui
 *
 */
public class SortDemo {
	private static Random random = new Random();
	/**
	 * 随机数的取值倍数
	 */
	private static final int MUTI = 2;

	/**
	 * 生成lenght长度的随机数数组
	 * 
	 * @param length
	 *            数组长度
	 * @return 随机数数组
	 * 
	 */
	public static int[] makeRandom(int length) {
		int[] nums = new int[length];
		for (int i = 0; i < nums.length; i++) {
			nums[i] = random.nextInt(length * MUTI);
		}
		return nums;
	}

	/**
	 * 显示数组nums中前length的数组
	 * 
	 * 
	 * @param nums
	 * @param length
	 */
	public static void showArray(int[] nums, int length) {
		for (int i = 0; i < nums.length; i++) {
			System.out.print(nums[i] + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		System.out.println("系統自帶排序======================================");
		int length = 100000;
		int[] nums = makeRandom(length);
		showArray(nums, 10);
		long start = System.currentTimeMillis();
		// arrays是系統
		//
		Arrays.sort(nums);
		long end = System.currentTimeMillis();
		System.out.printf("接續%s個數時間為%s%n", length, end - start);
		System.out.println(String.format("接續%s個數時間為%s%n", length, end - start));
		System.out.println(String.format("接續%s個數時間為%s%n", length,null));
		showArray(nums, 10);

		// System.out.println("冒泡排序===========================================");
		// int[] nums = makeRandom(10);
		// showArray(nums, nums.length);
		// BubbleSort.sort(nums);
		// showArray(nums, nums.length);
		// System.out.println("快速排序===========================================");
		// nums=makeRandom(10);
		// showArray(nums, nums.length);
		// QuickSort.sort(nums);
		// showArray(nums, nums.length);
		// System.out.println("時間成本==========================");
		// int length=100000;
		// nums=makeRandom(length);
		// long start=System.currentTimeMillis();
		// BubbleSort.sort(nums);
		// System.out.println("冒泡"+length+"個數的時間成本"+(System.currentTimeMillis()-start));
		// System.out.println("============================================================");
		// nums=makeRandom(length);
		// start=System.currentTimeMillis();
		// QuickSort.sort(nums);
		// System.out.println("排序"+length+"個數的時間成本"+(System.currentTimeMillis()-start));
	}

}
